﻿//-----------------------------------------------------------------------
// <copyright file="TestNhSessionFactoryCfg.cs" company="OverrideThis">
//     Copyright (c) 2010 OverrideThis.com
// </copyright>
//-----------------------------------------------------------------------
namespace OverrideThis.Core.Tests.Infrastructure.Repository.Impl.Cfg
{
    using System;
    using System.Reflection;
    using FluentNHibernate.Automapping;
    using FluentNHibernate.Cfg;
    using FluentNHibernate.Cfg.Db;
    using NHibernate.Cfg;
    using OverrideThis.Core.Infrastucture.Repository.Impl;
    using OverrideThis.Core.Tests.Infrastructure.Repository.Impl.Domain;

    public class TestNhSessionFactoryCfg : INhSessionFactoryCfg
    {
        #region Implementation of INhSessionFactoryConfig

        public Action<MappingConfiguration> Mapping()
        {
            return m => m.AutoMappings
                            .Add(
                                AutoMap.Assemblies(new CustomAutomappingConfiguration(), Assembly.GetAssembly(typeof(Person)))
                            );
        }

        public IPersistenceConfigurer Provider()
        {
            return SQLiteConfiguration.Standard.InMemory();
        }

        public void ExposeConfiguration(Configuration mapping)
        {
            // Do Nothing.
        }

        #endregion

        protected class CustomAutomappingConfiguration : DefaultAutomappingConfiguration
        {
            public override bool ShouldMap(Type type)
            {
                return type.Equals(typeof(Person));
            }
        }
    }
}